<?php
namespace app\home\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\home\model\OrdersModel;
use app\home\model\UserModel;
use app\home\model\CartsModel;

class Orders extends Common
{

	/**
	*	确认订单页
	*/
	public function corder()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$UserModel = new UserModel();
		$list = $OrdersModel->makeOrder($data['ids']);
		$address = $UserModel->getDefaultAddress();
		$user = $UserModel->getUser();
		/* 总金额 */
		$this->assign('total',$data['total']);
		/* 购物车信息 */
		$this->assign('list',$list);
		/* 登录用户的默认收货地址 */
		$this->assign('address',$address);
		/* 登录用户信息 */
		$this->assign('user',$user);
		/* 购物车的id */
		$this->assign('ids',$data['ids']);
		/* 购物车的商品id */
		$this->assign('gids',$data['gids']);
		return $this->fetch();
	}

	/**
	*	添加订单-订单信息
	*/
	public function addOrders()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->addUserOrders($data);
		if($list){
			return returnJson($code=0,$msg="提交成功",$list);
		}else{
			return returnJson($code=1,$msg="提交失败",$list);
		}
	}

	/**
	*	添加订单-商品信息
	*/
	public function addOrdersInfo()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->addOrdersInfo($data['ids'],$data['oid']);
		if($list){
			return returnJson($code=0,$msg="提交成功",$list);
		}else{
			return returnJson($code=1,$msg="提交失败",$list);
		}
	}
	

	/**
	*	付款成功页
	*/
	public function osuccess()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->OrderSuccess($data['id']);
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	已付款订单详情页
	*/
	public function haspayorder()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->getUserNorders($data['id']);
		$this->assign('list',$list['res']);
		$this->assign('address',$list['address']);
		return $this->fetch();
	}

	/**
	*	未付款订单详情页
	*/
	public function norder()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->getUserNorders($data['id']);
		$this->assign('list',$list['res']);
		$this->assign('address',$list['address']);
		return $this->fetch();
	}

	/**
	*	已取消详情页
	*/
	public function sorder()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->getUserNorders($data['id']);
		$this->assign('list',$list['res']);
		$this->assign('address',$list['address']);
		return $this->fetch();
	}

	/**
	*	未付款的订单-支付
	*/
	public function orderPay()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->orderPay($data['id'],$data);
		if($list){
			return returnJson($code=0,$msg="支付成功",$list);
		}else{
			return returnJson($code=1,$msg="支付失败",$list);
		}
	}

	/**
	*	取消订单
	*/
	public function deleteOrder()
	{
		$data = $this->request->param();
		$OrdersModel = new OrdersModel();
		$list = $OrdersModel->deleteOrder($data['id']);
		if($list){
			return returnJson($code=0,$msg='取消订单成功',$list);
		}else{
			return returnJson($code=1,$msg="取消订单失败",$list);
		}
	}

}